package com.example.gybicycle.controller.web;

import com.example.gybicycle.common.Log.SysLoging;
import com.example.gybicycle.common.entity.NormalPage;
import com.example.gybicycle.common.entity.Result;
import com.example.gybicycle.entity.MemberCycling;
import com.example.gybicycle.service.MemberCyclingService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "骑行记录")
@RestController
@RequestMapping("/web/memberCycling")
public class MemberCyclingController {
    @Autowired
    private MemberCyclingService memberCyclingService;
    @PostMapping("/get")
    @SysLoging("订单管理-查看")
    @Operation(summary = "根据id查看")
    @RequiresPermissions("cycling:list")
    @ApiOperationSupport(includeParameters = {"memberCycling.id"})
    public Result get(@RequestBody MemberCycling memberCycling){
      memberCycling=memberCyclingService.get(memberCycling.getId());
        return Result.success(memberCycling);
    }
    @PostMapping("/list")
    @Operation(summary =  "列表查看")
    @ApiOperationSupport(includeParameters = {"page.id","page.page","page.size","page.name","memberCycling.state"})
    @RequiresPermissions("cycling:list")
    @SysLoging("订单管理-查看")
    public Result findList(@RequestBody(required=false) MemberCycling page){
       
        Page<MemberCycling> list = PageHelper.startPage(page.getPage(), page.getSize()).doSelectPage(
                () ->memberCyclingService.findList(page));
        return Result.success(NormalPage.createPage(list));
    }

  @PostMapping("/delete")
    @Operation(summary =  "删除")
    @RequiresPermissions("cycling:delete")
    @SysLoging("订单管理-删除")
    public Result delete(@RequestBody MemberCycling entity){
        int num=memberCyclingService.delete(entity.getId());
        if(num>0)
            return Result.success("删除成功");
        else 
            return Result.fail("删除失败");
    }
     @PostMapping("deletelist")
    @Operation(summary =  "批量删除")
    @ApiOperationSupport(includeParameters = {"cycling.id"})
    @RequiresPermissions("cycling:delete")
    @SysLoging("订单管理-批量删除")
    public Result deletelist(@RequestBody List<String> data){
        int num=memberCyclingService.deleteByBatch(data);
         if(num>0)
             return Result.success("删除成功");
         else
             return Result.fail("删除失败"); 
    }
}